import java.util.ArrayList;
import java.util.List;

import use_case.handlereturns.DVD;
import use_case.handlereturns.Game;
import use_case.handlereturns.itemDescription;
import use_case.processRental.Checkout;
import use_case.processRental.RentUI;
import use_case.processRental.TotalListener;
import junit.framework.TestCase;


public class CheckoutTest extends TestCase {
		private Checkout checkout;
		DVD d1;
		Game g1;
		private List<TotalListener> listener;
		
		protected void setUp(){
			checkout = new Checkout();
			d1 = new DVD("Legend", "Action", 15312464);
			g1 = new Game("UFC", "Fighting", 15312464);
			listener = new ArrayList<TotalListener>();
			checkout.addItem(d1);
			checkout.addItem(g1);
			
		}
		
		protected void tearDown(){
			checkout = null;
			d1 = null;
			g1 = null;
			listener = null;
		}
		
		
		//***********************************************
		//Observer Pattern Test
		public void testAddTotalListener(){
			setUp();
			class Expected implements TotalListener{

				@Override
				public void onTotalPropertyEvent(String name, double total) {
					// TODO Auto-generated method stub
					
				}
				
			}
			checkout.addTotalListener(new Expected());
			assertTrue(checkout.getTotalListener(0) instanceof Expected);
			tearDown();
			
		}
		
		public void testPublishTotalEvent(){
			setUp();
			
			class Expected implements TotalListener{
				double expectedValue = 0;
				@Override
				public void onTotalPropertyEvent(String name, double total) {
					expectedValue = total;
				}
				
			}
			Expected obj1 = new Expected();
			checkout.addTotalListener(obj1);
			checkout.publishTotalEvent("Tamer", 33);
			assertTrue(obj1.expectedValue == 33);
			tearDown();
			obj1 = null;
		}
		//***********************************************
		
		//***********************************************
		// Strategy Pattern with Singleton Factory Test
		
		public void testImplementDiscountForPercent(){
			setUp();
			double expected = checkout.getTotal() - checkout.getTotal() * .1;
			checkout.implementDiscount("Percent");
			assertEquals(expected, checkout.getTotal());
			tearDown();
		}
		
		public void testImplementDiscountForCoupon(){
			setUp();
			double expected = checkout.getTotal() - 1;
			checkout.implementDiscount("Coupon");
			assertEquals(expected, checkout.getTotal());
			tearDown();
		}
		//***********************************************
		
		//***********************************************
		//Adaptor Pattern with Singleton Factory Test
		public void testAddTaxesForCounty(){
			setUp();
			double total = d1.getCost() + g1.getCost();
			double expected =  total + total*.07;
			assertEquals(expected, checkout.getTotal());
			tearDown();
		}
		
		public void testAddTaxesForCity(){
			setUp();
			checkout.changeTaxType("City");
			DVD d2 = new DVD("Legend", "Action", 15312464);
			checkout.addItem(d2);
			double total = d1.getCost() + g1.getCost() + d2.getCost();
			double expected =  total + total*.09;
			System.out.println(expected + ":" + checkout.getTotal());
			assertEquals(expected, checkout.getTotal());
			tearDown();
			d2 = null;
		}
		//***********************************************
		
		public void testAddItem(){
			setUp();
			Game expected = new Game("UFC", "Fighting", 15312464);
			assertEquals(expected.getID(), checkout.getItem(1).getID());
			tearDown();
		}
		
		
		public void testUpdateTotalAndAddTaxes(){
			setUp();
			assertEquals(3.21, checkout.getTotal());
			tearDown();			
		}
		
		public void testGetSelectedList(){
			setUp();
			
			String[] expected= new String[checkout.getCartSize()];
			expected[0] = d1.getName() +"\t" +"$"+ d1.getCost();
			String[] result = checkout.getSelectedList();
			
			assertEquals(expected[0], result[0]);
			
			tearDown();	
		}
		
		
		public void testRemoveItemFromCart(){
			setUp();
			checkout.removeItemFromCart(1);
			assertEquals(1,checkout.getCartSize());
			tearDown();
		}
		
		public void testCartSize(){
			setUp();
			assertEquals(2, checkout.getCartSize());
			tearDown();
		}
		
		public void testGetItem(){
			setUp();
			assertEquals(d1, checkout.getItem(0));
			tearDown();
		}
		
		
		
		
	
		
}
